package com.diy.sigmund.diyuser.test.controller;

import com.diy.sigmund.diycommon.entity.ResultMsg;
import com.diy.sigmund.diycommon.spring.anno.ApiIdempotent;
import com.diy.sigmund.diycommon.spring.anno.IgnoreTokenVerification;
import com.diy.sigmund.diycommon.spring.service.ApiIdempotentService;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ylm-sigmund
 * @since 2021/8/17 12:03
 */
@RestController
@RequestMapping("/user/apiIdempotent")
public class ApiIdempotentController {

    @Autowired
    private ApiIdempotentService apiIdempotentService;

    @IgnoreTokenVerification
    @PostMapping("/get/token")
    public ResultMsg getToken() {
        String token = apiIdempotentService.createToken();
        if (StringUtils.isNotEmpty(token)) {
            return ResultMsg.success(token);
        }
        return ResultMsg.success(StringUtils.EMPTY);
    }

    @ApiIdempotent
    @PostMapping("/test/Idempotence")
    public ResultMsg testIdempotence(HttpServletRequest req) {
        return ResultMsg.success("aaa！");
    }

}
